//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.ObjectModel;
using OpenLS.Core.Serialization;

namespace OpenLS.Chart
{
    public abstract class SurfaceChartBase : ChartBase
    {
        private ObservableCollection<SurfaceSeries> _series;
        private ObservableCollection<BandFormat> bandFormats = new ObservableCollection<BandFormat>();
        private bool wireframe;

        public bool WireFrame
        {
            get { return wireframe; }
            set { wireframe = value; }
        }

        public ObservableCollection<SurfaceSeries> Series
        {
            get
            {
                if (_series == null)
                    _series = CreateSeriesCollection<SurfaceSeries>();
                return _series;
            }
        }

        public ObservableCollection<BandFormat> BandFormats
        {
            get { return bandFormats; }
            set { bandFormats = value; }
        }

        protected void ReadXmlBase(ReadContext c)
        {
            WireFrame = c.ReadOptionalElementBooleanAttribute("wireframe",false);
            Series.Clear();
            while (c.ReaderLocalName == "ser")
            {
                SurfaceSeries s = new SurfaceSeries();
                s.ReadXmlCore(c);
                Series.Add(s);
            }
            BandFormats.Clear();
            foreach (BandFormat obj in c.ReadElements<BandFormat>("bandFmts", "bandFmt"))
                BandFormats.Add(obj);
        }

        protected void WriteXmlBase(WriteContext c)
        {
            c.WriteOptionalElementBooleanAttribute("wireframe", WireFrame, false);
            foreach (SurfaceSeries s in Series)
                c.WriteElement(s);
            if (BandFormats.Count > 0)
            {
                using (WriteContext c2 = c.Write("bandFmts"))
                {
                    foreach (BandFormat f in BandFormats)
                        c2.WriteElement(f);
                }
            }
        }
    }
}